home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_010 / iff / ilbm.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  11KB  |  243 lines

  1. #ifndef ILBM_H
  2. #define ILBM_H
  3. /*----------------------------------------------------------------------*
  4.  * ILBM.H  Definitions for InterLeaved BitMap raster image.    11/15/85
  5.  *
  6.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  7.  * This software is in the public domain.
  8.  *
  9.  * This version for the Commodore-Amiga computer.
  10.  *----------------------------------------------------------------------*/
  11. #ifndef EXEC_TYPES_H
  12. #include <exec/types.h>
  13. #endif
  14.  
  15. #ifndef GRAPHICS_GFX_H
  16. #include <graphics/gfx.h>
  17. #endif
  18.  
  19. #include "iff.h"
  20.  
  21. #define ID_ILBM MakeID('I','L','B','M')
  22. #define ID_BMHD MakeID('B','M','H','D')
  23. #define ID_CMAP MakeID('C','M','A','P')
  24. #define ID_GRAB MakeID('G','R','A','B')
  25. #define ID_DEST MakeID('D','E','S','T')
  26. #define ID_SPRT MakeID('S','P','R','T')
  27. #define ID_CAMG MakeID('C','A','M','G')
  28. #define ID_BODY MakeID('B','O','D','Y')
  29.  
  30. /* ---------- BitMapHeader ---------------------------------------------*/
  31.  
  32. typedef UBYTE Masking;          /* Choice of masking technique.*/
  33. #define mskNone                 0L
  34. #define mskHasMask              1L
  35. #define mskHasTransparentColor  2L
  36. #define mskLasso                3L
  37.  
  38. typedef UBYTE Compression;      /* Choice of compression algorithm applied to
  39.      * each row of the source and mask planes. "cmpByteRun1" is the byte run
  40.      * encoding generated by Mac's PackBits. See Packer.h . */
  41. #define cmpNone      0L
  42. #define cmpByteRun1  1L
  43.  
  44. /* Aspect ratios: The proper fraction xAspect/yAspect represents the pixel
  45.  * aspect ratio pixel_width/pixel_height.
  46.  *
  47.  * For the 4 Amiga display modes:
  48.  *   320 x 200: 10/11  (these pixels are taller than they are wide)
  49.  *   320 x 400: 20/11
  50.  *   640 x 200:  5/11
  51.  *   640 x 400: 10/11           */
  52. #define x320x200Aspect 10L
  53. #define y320x200Aspect 11L
  54. #define x320x400Aspect 20L
  55. #define y320x400Aspect 11L
  56. #define x640x200Aspect  5L
  57. #define y640x200Aspect 11L
  58. #define x640x400Aspect 10L
  59. #define y640x400Aspect 11L
  60.  
  61. /* A BitMapHeader is stored in a BMHD chunk. */
  62. typedef struct {
  63.     UWORD w, h;                 /* raster width & height in pixels */
  64.     WORD  x, y;                 /* position for this image */
  65.     UBYTE nPlanes;              /* # source bitplanes */
  66.     Masking masking;            /* masking technique */
  67.     Compression compression;    /* compression algoithm */
  68.     UBYTE pad1;                 /* UNUSED.  For consistency, put 0 here.*/
  69.     UWORD transparentColor;     /* transparent "color number" */
  70.     UBYTE xAspect, yAspect;     /* aspect ratio, a rational number x/y */
  71.     WORD  pageWidth, pageHeight;  /* source "page" size in pixels */
  72.     } BitMapHeader;
  73.  
  74. /* RowBytes computes the number of bytes in a row, from the width in pixels.*/
  75. #define RowBytes(w)   (((w) + 15) >> 4 << 1)
  76.  
  77.  
  78. /* ---------- ColorRegister --------------------------------------------*/
  79. /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */
  80. typedef struct {
  81.     UBYTE red, green, blue;   /* MUST be UBYTEs so ">> 4" won't sign extend.*/
  82.     } ColorRegister;
  83.  
  84. /* Use this constant instead of sizeof(ColorRegister). */
  85. #define sizeofColorRegister  3L
  86.  
  87. typedef WORD Color4;    /* Amiga RAM version of a color-register,
  88.                          * with 4 bits each RGB in low 12 bits.*/
  89.  
  90. /* Maximum number of bitplanes in RAM. Current Amiga max w/dual playfield. */
  91. #define MaxAmDepth 6L
  92.  
  93. /* ---------- Point2D --------------------------------------------------*/
  94. /* A Point2D is stored in a GRAB chunk. */
  95. typedef struct {
  96.     WORD x, y;          /* coordinates (pixels) */
  97.     } Point2D;
  98.  
  99. /* ---------- DestMerge ------------------------------------------------*/
  100. /* A DestMerge is stored in a DEST chunk. */
  101. typedef struct {
  102.     UBYTE depth;        /* # bitplanes in the original source */
  103.     UBYTE pad1;         /* UNUSED; for consistency store 0 here */
  104.     UWORD planePick;    /* how to scatter source bitplanes into destination */
  105.     UWORD planeOnOff;   /* default bitplane data for planePick */
  106.     UWORD planeMask;    /* selects which bitplanes to store into */
  107.     } DestMerge;
  108.  
  109. /* ---------- SpritePrecedence -----------------------------------------*/
  110. /* A SpritePrecedence is stored in a SPRT chunk. */
  111. typedef UWORD SpritePrecedence;
  112.  
  113. /* ---------- Viewport Mode --------------------------------------------*/
  114. /* A Commodore Amiga ViewPort->Modes is stored in a CAMG chunk. */
  115. /* The chunk's content is declared as a LONG. */
  116.  
  117. /* ---------- CRange ---------------------------------------------------*/
  118. /* A CRange is store in a CRNG chunk. */
  119. typedef struct {
  120.     WORD  pad1;         /* reserved for future use; store 0 here */
  121.     WORD  rate;         /* color cycling rate, 16384 = 60 steps/second */
  122.     WORD  active;       /* nonzero means color cycling is turned on */
  123.     UBYTE low, high;    /* lower and upper color registers selected */
  124.     } CRange;
  125.  
  126. /* ---------- ILBM Writer Support Routines -----------------------------*/
  127.  
  128. /* Note: Just call PutCk to write a BMHD, GRAB, DEST, SPRT, or CAMG
  129.  * chunk. As below. $$$ - Casted "sizeof" to "longs" below */
  130. #define PutBMHD(context, bmHdr)  \
  131.     PutCk(context, ID_BMHD, (long)sizeof(BitMapHeader), (BYTE *)bmHdr)
  132. #define PutGRAB(context, point2D)  \
  133.     PutCk(context, ID_GRAB, (long)sizeof(Point2D), (BYTE *)point2D)
  134. #define PutDEST(context, destMerge)  \
  135.     PutCk(context, ID_DEST, (long)sizeof(DestMerge), (BYTE *)destMerge)
  136. #define PutSPRT(context, spritePrec)  \
  137.     PutCk(context, ID_SPRT, (long)sizeof(SpritePrecedence), (BYTE *)spritePrec)
  138.  
  139. /* Initialize a BitMapHeader record for a full-BitMap ILBM picture.
  140.  * This gets w, h, and nPlanes from the BitMap fields BytesPerRow, Rows, and
  141.  * Depth. It assumes you want  w = bitmap->BytesPerRow * 8 .
  142.  * CLIENT_ERROR if bitmap->BytesPerRow isn't even, as required by ILBM format.
  143.  *
  144.  * If (pageWidth, pageHeight) is (320, 200), (320, 400), (640, 200), or
  145.  * (640, 400) this sets (xAspect, yAspect) based on those 4 Amiga display
  146.  * modes. Otherwise, it sets them to (1, 1).
  147.  *
  148.  * After calling this, store directly into the BitMapHeader if you want to
  149.  * override any settings, e.g. to make nPlanes smaller, to reduce w a little,
  150.  * or to set a position (x, y) other than (0, 0).*/
  151. extern IFFP InitBMHdr(/* BitMapHeader *, struct BitMap *,
  152.                          bmHdr,          bitmap
  153.      int,     int,         int,              int,       int*/);
  154.  /*  masking, compression, transparentColor, pageWidth, pageHeight  */
  155.  /*  Masking, Compression, UWORD,            WORD,      WORD  */
  156.  
  157. /* Output a CMAP chunk to an open FORM ILBM write context. */
  158. extern IFFP PutCMAP(/*GroupContext *, WORD *,   UBYTE  */);
  159.                     /*context,        colorMap, depth  */
  160.  
  161. /* This procedure outputs a BitMap as an ILBM's BODY chunk with
  162.  * bitplane and mask data. Compressed if bmHdr->compression == cmpByteRun1.
  163.  * If the "mask" argument isn't NULL, it merges in the mask plane, too.
  164.  * (A fancier routine could write a rectangular portion of an image.)
  165.  * This gets Planes (bitplane ptrs) from "bitmap".
  166.  *
  167.  * CLIENT_ERROR if bitmap->Rows != bmHdr->h, or if
  168.  * bitmap->BytesPerRow != RowBytes(bmHdr->w), or if
  169.  * bitmap->Depth < bmHdr->nPlanes, or if bmHdr->nPlanes > MaxAmDepth, or if
  170.  * bufsize < MaxPackedSize(bitmap->BytesPerRow), or if
  171.  * bmHdr->compression > cmpByteRun1. */
  172. extern IFFP PutBODY(/*
  173.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG */);
  174.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  175.  
  176. /* ---------- ILBM Reader Support Routines -----------------------------*/
  177.  
  178. /* Note: Just call IFFReadBytes to read a BMHD, GRAB, DEST, SPRT, or CAMG
  179.  * chunk. As below. Casted "sizeof's" to "longs" */
  180. #define GetBMHD(context, bmHdr)  \
  181.     IFFReadBytes(context, (BYTE *)bmHdr, (long)sizeof(BitMapHeader))
  182. #define GetGRAB(context, point2D)  \
  183.     IFFReadBytes(context, (BYTE *)point2D, (long)sizeof(Point2D))
  184. #define GetDEST(context, destMerge)  \
  185.     IFFReadBytes(context, (BYTE *)destMerge, (long)sizeof(DestMerge))
  186. #define GetSPRT(context, spritePrec)  \
  187.     IFFReadBytes(context, (BYTE *)spritePrec, (long)sizeof(SpritePrecedence))
  188.  
  189. /* Input a CMAP chunk from an open FORM ILBM read context.
  190.  * This converts to an Amiga color map: 4 bits each of red, green, blue packed
  191.  * into a 16 bit color register.
  192.  * pNColorRegs is passed in as a pointer to a UBYTE variable that holds
  193.  * the number of ColorRegisters the caller has space to hold. GetCMAP sets
  194.  * that variable to the number of color registers actually read.*/
  195.  
  196. extern IFFP GetCMAP(/*GroupContext *, WORD *,   UBYTE **/);
  197.                   /*  context,        colorMap, pNColorRegs  */
  198.  
  199. /* GetBODY can handle a file with up to 16 planes plus a mask.*/
  200. #define MaxSrcPlanes 16+1
  201.  
  202. /* GetBODY reads an ILBM's BODY into a client's bitmap, de-interleaving and
  203.  * decompressing.
  204.  *
  205.  * Caller should first compare bmHdr dimensions (rowWords, h, nPlanes) with
  206.  * bitmap dimensions, and consider reallocating the bitmap.
  207.  * If file has more bitplanes than bitmap, this reads first few planes (low
  208.  * order ones). If bitmap has more bitplanes, the last few are untouched.
  209.  * This reads the MIN(bmHdr->h, bitmap->Rows) rows, discarding the bottom
  210.  * part of the source or leaving the bottom part of the bitmap untouched.
  211.  *
  212.  * GetBODY returns CLIENT_ERROR if asked to perform a conversion it doesn't
  213.  * handle. It only understands compression algorithms cmpNone and cmpByteRun1.
  214.  * The filed row width (# words) must agree with bitmap->BytesPerRow.
  215.  *
  216.  * Caller should use bmHdr.w; GetBODY only uses it to compute the row width
  217.  * in words. Pixels to the right of bmHdr.w are not defined.
  218.  *
  219.  * [TBD] In the future, GetBODY could clip the stored image horizontally or
  220.  * fill (with transparentColor) untouched parts of the destination bitmap.
  221.  *
  222.  * GetBODY stores the mask plane, if any, in the buffer pointed to by mask.
  223.  * If mask == NULL, GetBODY will skip any mask plane. If
  224.  * (bmHdr.masking != mskHasMask) GetBODY just leaves the caller's mask alone.
  225.  *
  226.  * GetBODY needs a buffer large enough for two compressed rows.
  227.  * It returns CLIENT_ERROR if bufsize < 2 * MaxPackedSize(bmHdr.rowWords * 2).
  228.  *
  229.  * GetBODY can handle a file with up to MaxSrcPlanes planes. It returns
  230.  * CLIENT_ERROR if the file has more. (Could be due to a bum file, though.)
  231.  * If GetBODY fails, it might've modified the client's bitmap. Sorry.*/
  232. extern IFFP GetBODY(/*
  233.     GroupContext *, struct BitMap *, BYTE *, BitMapHeader *, BYTE *, LONG*/);
  234.     /*  context,           bitmap,   mask,   bmHdr,         buffer, bufsize */
  235.  
  236. /* [TBD] Add routine(s) to create masks when reading ILBMs whose
  237.  * masking != mskHasMask. For mskNone, create a rectangular mask. For
  238.  * mskHasTransparentColor, create a mask from transparentColor. For mskLasso,
  239.  * create an "auto mask" by filling transparent color from the edges. */
  240.  
  241. #endif
  242.  
  243.